//
//  TopMeView.m
//  intelligent
//
//  Created by 甘世清 on 2024/2/6.
//

#import "TopMeView.h"
#import "MeVipViewController.h"
@implementation TopMeView

- (void)SQ_UIViewForSelfView{
    UIImageView * bgImage = [[UIImageView alloc]init];
    bgImage.image = SQGetImage(@"背景");
    bgImage.clipsToBounds = YES;
    bgImage.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:bgImage];
    [bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self addSubview:self.avatarImageView];
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-30);
        make.size.mas_equalTo(88);
        make.left.equalTo(self).offset(12);
    }];
    [self addSubview:self.topLabel];
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.avatarImageView).offset(16);
        make.height.mas_equalTo(28);
        make.left.equalTo(self).offset(112);
    }];
    [self addSubview:self.messageLabel];
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.avatarImageView.mas_bottom).offset(-16);
        make.height.mas_equalTo(20);
        make.left.equalTo(self).offset(112);
    }];
    [self addSubview:self.rightButton];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.avatarImageView);
            make.height.mas_equalTo(40);
            make.width.mas_equalTo(130);
        make.right.equalTo(self.mas_right).offset(20);
    }];
    
    [self.rightButton setTouchBlock:^(SQCustomButton * _Nonnull button) {
        MeVipViewController  * vc = [[MeVipViewController alloc]init];
        [[Manager SQ_getCurrentViewController].navigationController pushViewController:vc animated:YES];
    }];
    
    
   
    
}
- (void)SQ_Data{
    UserModel * model = [UserModel share];
    self.avatarImageView.image = model.portraitname;
   
    self.topLabel.text =model.name;
    if (model.isVip) {
        self.messageLabel.text = @"";
        self.rightButton.text = SQNSLocalString(@"VIP已开通");
        self.rightButton.backgroundColor = SQColor(@"4AF8CE");
        _rightButton.textColor = SQColor(@"#000000");
    } else {
        _rightButton.backgroundColor = SQColor333333;
        _rightButton.text = SQNSLocalString(@"VIP暂未开通");
        _rightButton.textColor = SQColor(@"#FFFFFF");
        self.messageLabel.text = [NSString stringWithFormat:@"%@%@",SQNSLocalString(@"当前咨询剩余次数："),model.freeCount]; ;
    }
   
}
- (HeaderView *)avatarImageView{
    if (!_avatarImageView) {
        _avatarImageView = [[HeaderView alloc]init];
        _avatarImageView.clipsToBounds = YES;
        _avatarImageView.layer.cornerRadius = 8;
        _avatarImageView.layer.masksToBounds = YES;
        _avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _avatarImageView;
}
- (UILabel *)topLabel{
    if (!_topLabel) {
        _topLabel = [[UILabel alloc]init];
        _topLabel.font = FONT_MEDIUM(20);
        _topLabel.textColor = SQColor333333;
        _topLabel.backgroundColor = UIColor.clearColor;
        _topLabel.numberOfLines = 0;
//        _messageLabel.textAlignment = NSTextAlignmentRight;
    }
    return _topLabel;
}
- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc]init];
        _messageLabel.font = FONT_MEDIUM(14);
        _messageLabel.textColor = SQColor333333;
        _messageLabel.backgroundColor = UIColor.clearColor;
        _messageLabel.numberOfLines = 0;
//        _messageLabel.textAlignment = NSTextAlignmentRight;
    }
    return _messageLabel;
}
- (SQCustomButton *)rightButton{
    if (!_rightButton) {
        _rightButton = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(0, 0) midmargin:0];
        _rightButton.layer.cornerRadius = 20;
        _rightButton.layer.masksToBounds = YES;
        _rightButton.backgroundColor = SQColor333333;
        _rightButton.text = SQNSLocalString(@"VIP暂未开通");
        _rightButton.font = FONT_MEDIUM(14);
        _rightButton.textColor = SQColor(@"#FFFFFF");
    }
    return _rightButton;
}


@end
